package org.despair2D.ui.core 
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.despair2D.core.EventDispatcherAdvance;
	import org.despair2D.core.ProcessManager;
	import org.despair2D.debug.Logger;
	import org.despair2D.renderer.IView;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.Fusion;
	
	import org.despair2D.core.ns_despair;
	use namespace ns_despair;
	
	/** @inheritDoc **/
public class Component extends SpriteAdvance
{
	
	public function Component()
	{
		UIManager.registerComp(this)
	}
	
	
	final public function get layer() : int { return (this.parent) ? this.parent.getChildIndex(this) : -1 }
	
	final public function get spaceWidth() : Number { return (m_spaceWidth <= 0 || isNaN(m_spaceWidth)) ? this.width : m_spaceWidth }
	final public function set spaceWidth( v:Number ) : void { m_spaceWidth = v }
	
	final public function get spaceHeight() : Number { return (m_spaceHeight <= 0 || isNaN(m_spaceHeight)) ? this.height : m_spaceHeight }
	final public function set spaceHeight( v:Number ) : void { m_spaceHeight = v }
	
	
	final override public function addEventListener ( type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ) : void
	{
		m_eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
	}
	
	final override public function removeEventListener ( type:String, listener:Function, useCapture:Boolean = false ) : void
	{
		m_eventDispatcher.removeEventListener(type, listener, useCapture);
	}
	
	final override public function dispatchEvent ( event:Event ) : Boolean
	{
		return m_eventDispatcher.dispatchEvent(event);
	}
	
	final override public function hasEventListener ( type:String ) : Boolean
	{
		return m_eventDispatcher.hasEventListener(type);
	}
	
	final override public function willTrigger ( type:String ) : Boolean
	{
		return m_eventDispatcher.willTrigger(type);
	}
	
	final public function removeAllEventListeners() : void
	{
		m_eventDispatcher.removeAllEventListeners()
	}
	
	final public function bePartOf ( c:IComponent ) : Boolean
	{
		var FN:Fusion
		
		if (c == m_proxy)
		{
			return true
		}
		
		FN = IComponent(m_proxy).fusion
		while (FN)
		{
			if (FN == c)
			{
				return true;
			}
			FN = FN.fusion;
		}
		return false;
	}
	
	override ns_despair function dispose() : void
	{
		m_eventDispatcher.dispatchEvent(new ManipulateEvent(ManipulateEvent.KILLED));
		m_spaceWidth = m_spaceHeight = NaN
		m_eventDispatcher.removeAllEventListeners();
		super.dispose()
	}
	
	
	ns_despair var m_eventDispatcher:EventDispatcherAdvance
	
	ns_despair var m_proxy:IView
	
	ns_despair var m_cid:uint
	
	ns_despair var m_spaceWidth:Number, m_spaceHeight:Number
}
}